<form {if $id>0}action="{php echo webUrl('exchange/coupon/edit',array('id'=>$id),true);}"{else}action="
    {php echo webUrl('exchange/coupon/add',array(),true);}"{/if} method="post" class="form-validate">
    <div class="modal-dialog" style="width: 450px">
        <div class="modal-content">
            <div class="modal-body">
                <div class="row">
                    <div id="goods" style="display: none">
                        <h3>请选择优惠券</h3>
                        <!--搜索条-->
                        <div class="modal-body" style="width: 80%;margin-left: 10%;">
                            <div class="row">
                                <div class="input-group">
                                    <input type="text" class="form-control" name="keyword" id="goodsid_input"
                                           placeholder="请输入关键词">
                                    <span class="input-group-btn">
                                            <button type="button" class="btn btn-default"
                                                    onclick="biz.selector_new.search(this, 'goodsid');">搜索</button>
                                        </span>
                                </div>
                            </div>
                        </div>

                        <div style="max-height:500px;overflow:auto;min-width:500px;">
                            <table class="table">
                                <thead>
                                <tr>
                                    <td style="width: 20%">排序</td>
                                    <td style="width: 30%">优惠券名称</td>
                                    <td style="width:30%">参与兑换量</td>
                                    <td>是否选择</td>
                                </tr>
                                </thead>
                                <tbody class="ui-sortable">
                                {loop $all $key $value}
                                <tr>
                                    <td>1</td>
                                    <td>{$value['couponname']}</td>
                                    <td>
                                        <a href="javascript:;" data-toggle="ajaxEdit"
                                           data-href="{php echo webUrl('exchange/coupon/stock',array('goodsid'=>$value['id']));}"
                                           style="display: inline;">{$value['id']}</a>
                                    </td>
                                    <td>
                                        <div class="onoffswitch">
                                            <input type="checkbox" name="checkbox[]"
                                                   class="onoffswitch-checkbox" id="no{$value['id']}"
                                                   value="{$value['id']}" {if in_array($value['id'],$coupon)}checked{/if}>
                                            <label class="onoffswitch-label" for="no{$value['id']}">
                                                <span class="onoffswitch-inner"></span>
                                                <span class="onoffswitch-switch"></span>
                                            </label>
                                        </div>
                                    </td>
                                </tr>
                                {/loop}
                                </tbody>
                            </table>
                        </div>
                        <span class="btn btn-primary btn-outline"
                              onclick="$('#goods').hide();$('#edit').show();$('.modal-dialog').css('width','450px');">
                                选好了
                        </span>
                    </div>
                </div>
                <div class="row" id="edit">
                    <div class="col-sm-12">
                        <h3>{if $id>0}编辑优惠券兑换任务{else}添加优惠券兑换任务{/if}</h3><br>
                        <label>兑换任务标题：</label>
                        <input type="text" placeholder="请输入标题" class="form-control" name="title"
                               value="{$setting['title']}">
                        <br>
                        <label>开始时间：</label>
                        {php echo tpl_form_field_date('starttime',$setting['starttime'],true);}
                        <br>
                        <label>截止时间：</label>
                        {php echo tpl_form_field_date('endtime',$setting['endtime'],true);}
                        <br>

                        <label>选择优惠券：</label><br>

                        <button class="form-control" type="button" id="select">点击选择优惠券</button>
                        <br>
                        <label>兑换模式:</label><br>
                        <input type="radio" name="type" class="type" value="1" id="bdadd" {if $setting['type']==1}checked{/if}><label for="bdadd"> 发放所有选中优惠券</label>&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="type" class="type" value="2" id="adadd" {if $setting['type']==2}checked{/if}><label for="adadd"> 从选中的优惠券中随机发放一个</label>
                        <br><br>
                    </div>
                    <br>
                    <div style="margin-top: 10px;text-align: center">
                        <button type="submit" class="btn btn-primary">
                            {if $id>0}保存{else}添加{/if}
                        </button>
                        <button type="button" class="btn btn-primary btn-outline" data-dismiss="modal">
                            取消
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<script type="text/javascript">
    $(document).ready(function () {
        $('#select').click(function () {
            $('.modal-dialog').css('width', '800px');
            $('#goods').show();
            $('#edit').hide();
        });
    });
</script>
